import {defineConfig, loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
import {resolve} from 'path'
import {VantResolver} from "unplugin-vue-components/resolvers";
import Components from 'unplugin-vue-components/vite';
// https://vitejs.dev/config/
export default defineConfig(({mode}) => {
    const env = loadEnv(mode, process.cwd());
    return (
        {
            base: env.VITE_BASE_PATH,
            plugins: [
                vue(),
                Components({
                    resolvers: [VantResolver()],
                })
            ],
            resolve: {
                alias: {
                    "@": resolve(__dirname, "src"),
                    '@assets': resolve(__dirname, 'src/assets')
                }
            },
            server: {
                hmr: true,
                port: 4173,
                proxy: {
                    // 选项写法
                    '^/api': {
                        target: env.VITE_API_URL,
                        changeOrigin: true,
                        rewrite: (path) => path.replace(/^\/api/, '')
                    }, // 选项写法
                    // 选项写法
                    '^/assets': {
                        target: env.VITE_API_URL,
                        changeOrigin: true,
                        rewrite: (path) => path.replace(/^\/assets/, env.VITE_STATIC_PATH)
                    }, // 选项写法
                }
            },
            css: {
                // css预处理器
                preprocessorOptions: {
                    scss: {
                        charset: false,
                        //需要在assets下创建对应的文件global.scss
                        // additionalData: '@import "./src/assets/style/global.scss";',
                    },
                },
            }
        }
    )
})
